package com.yunhe.device.repository.base;

import com.yunhe.device.domain.base.DeviceType;
import com.yunhe.device.domain.base.PointDataType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName AnalogTypeRepository
 * @Description TODO
 * @Author HeTao
 * @Date 2021/7/13 17:59
 * @Version 1.0
 **/
@Repository
public interface AnalogTypeRepository extends Neo4jRepository<PointDataType, Long> {
    PointDataType findByTitle(String title);

    PointDataType findByName(String name);

    @Query("match(et:DeviceType)-[:HAS_ANLOGTYPE]->(at:PointDataType) where ID(at)={id} return et ")
    List<DeviceType> findAnlogTypeById(@Param("id") Long id);

    @Query("match(et:DeviceType{name:{equipName}})-[ha:HAS_ANLOGTYPE]->(at:PointDataType{activity:'1'}) where  (ha.stationId is null or ha.stationId={stationId})  return at ")
    List<PointDataType> getAnlogTypeByEquipTypeName(@Param("equipName") String equipName,@Param("stationId") Long stationId);

    List<PointDataType> findByActivityAndBackType(String activity,String backType);

    @Query(value="match(et:DeviceType{name:{equipName}})-[:HAS_ANLOGTYPE]->(at:PointDataType) where ID(et)={id}  return at",
            countQuery="match(et:DeviceType{name:{equipName}})-[:HAS_ANLOGTYPE]->(at:PointDataType) where ID(et)={id}  return count(at)")
    Page<PointDataType> getAnlogTypeByEquipTypeId(@Param("id") Long id, Pageable pageable);

    @Query("match(et:DeviceType)-[:HAS_ANLOGTYPE]->(at:PointDataType) where ID(et)={id}  return at")
    List<PointDataType> getAnlogTypesByEquipTypeId(@Param("id") Long id);
}
